<template>
  <div>
    <div class="top">
      <div class="top-a">
        <img :src="data.url" alt="">
       <div class="title">
        <h2>{{ idList.title }}</h2>
        <p>{{ idList.description }}</p>
       </div>
      </div>
      <div class="arr">
        <div class="item" v-for="item,i in data.arrList" :key="item._id">
          <h3 @click="gotitle(item._id)">{{ item.title }}</h3>
          <div class="img">
            <img v-if="item.image" :src="item.image.url" alt="">
            <p>{{ item.excerpt }}</p>
          </div>
          <p>{{ item.createdAt }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang='ts'  setup>
import {getid,getidList} from "../utlis/api"
import {ref, reactive, toRefs} from 'vue'
import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const route = useRoute()
const store = useStore()
const idList=ref([])
const data=reactive({
  url:"",
  arrList:[]
})
const params=reactive({
  page:1,
  size:3,
})
const id=route.query.id
console.log(id);
// 请求数据头像数据
getid(id).then(res=>{
    idList.value=res.data
    data.url=res.data.avatar.url
    console.log(idList,25);
  })
  //请求列表数据
  const listData=()=>{
    getidList(params,id).then(res=>{
      console.log(45,res);
      data.arrList=res.data.list
    })
  }
  //跳转详情页面
  const gotitle=(id:any)=>{
    router.push({
      path:"/title",
      query:{
        id
      }
    })
  }
  listData()
</script>

<style scoped lang='scss'>
.top{
  width: 800px;
  margin: auto;
  .top-a{
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    border-bottom: 1px solid #ccc;
    .title{
      margin-left: 30px;
    }
    img{
      width: 150px;
      height: 150px;
      border-radius: 50%;
    }
  }
  .arr{
    width: 100%;
    .item{
      width: 100%;
      border: 1px solid #ccc;
      padding: 10px;
      box-sizing: border-box;
      margin:20px 0;
      
      .img{
        width: 100%;
        display: flex;
        img{
          width: 300px;
          height: 180px;
        }
        p{
          margin-left: 10px;
        }
      }
    }
  }
}
</style>